
var jsonData={};
var Postdata={};
var qrlink='';
$(function(){
    var weixinInfo = {
        isWX: window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == "micromessenger" ? true : false
    };

    if (typeof WeixinJSBridge == "undefined"){
        if( document.addEventListener ){
            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
        }else if (document.attachEvent){
        document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
        document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
        }
    }else{
        onBridgeReady();
    }
 
    
    qrlink=window.location.href;
    getQrcode();
    getQuestion();
    bindEvent();
});
function onBridgeReady(){
        WeixinJSBridge.call('hideOptionMenu');
        wx.hideOptionMenu();
    }
function showData(){
    $(".qrcodeImg").show();
}
function getQrcode(){
    var args=getQueryStringArgs();
   var Postdatas={};
    if(args['tocken']!=undefined){
        Postdatas.tocken=args['tocken'];
    }else{
        Postdatas.tocken='';
    }
    if(args['serialId']!=undefined){
        Postdatas.SerialId=args['serialId'];
    }else{
        Postdatas.SerialId='';
    }
    if(args['memberId']!=undefined){
        Postdatas.MemberId=args['memberId'];
    }else{
        Postdatas.MemberId='';
    }
    if(args['returnurl']!=undefined){
        Postdatas.ReturnUrl=args['returnurl'];
    }else{
        Postdatas.ReturnUrl='';
    }
    if(args['jobnumber']!=undefined){
        Postdatas.FactorNo=args['jobnumber'];
    }else{
        Postdatas.FactorNo='';
    }
}
function bindEvent(){
    $(".survey_container").on("click",".option_item",function(e){
        e.preventDefault();
        var rel=$(this).find("a").attr("rel");
        var input=$("#"+rel);
        if(input[0].disabled){
            return;
        }
        if(input.attr("type")=="radio"){
            if($(window).width()<800){
                $(this).parents(".question").css("border-color","#f7f7f7");
            }else{
                $(this).parents(".question").css("border-color","white");
            }
            $(this).parents(".question").find(".errorMessage").html('');
            $(this).siblings().find("a").removeClass("jqChecked");
            $(this).find("a").addClass("jqChecked");
            input.prop("checked",true);
        }else{
            if($(window).width()<800){
                $(this).parents(".question").css("border-color","#f7f7f7");
            }else{
                $(this).parents(".question").css("border-color","white");
            }
            $(this).parents(".question").find(".errorMessage").html('');
            var checkBox=input.prop("checked");
            
            input.prop("checked",!checkBox);
            if(input.prop("checked")){
                $(this).find("a").addClass("jqChecked");
                if($(this).attr("IsMutex")=="true"){
                    $(this).siblings(".option_item").find("a").removeClass("jqChecked");
                    $(this).siblings(".option_item").find("input[type=checkbox]").prop("checked",false);
                    $(this).parents(".question").find(".underline").val('');
                }else{
                    $(this).siblings(".option_item[IsMutex=true]").find("a").removeClass("jqChecked");
                    $(this).siblings(".option_item[IsMutex=true]").find("input[type=checkbox]").prop("checked",false);
                    if($(this).attr("IsHavingOther")!=undefined){
                        $(this).find("input[type=text]").focus();
                        $(this).parents(".question").css("border","2px solid rgb(255, 153, 0)");
                        $(this).parents(".question").find(".errorMessage").html('选择其他，请填写输入框');
                    }
                }
                
            }else{
                if($(this).attr("IsHavingOther")!=undefined){
                    $(this).find("input[type=text]").val('');
                }
                $(this).find("a").removeClass("jqChecked");
            }
        }
    });
    $(".survey_container").on('click','input[type=text].underline',function(e){
        e.stopPropagation();
    });
    $(".survey_container").on('blur','.underline',function(e){
        if($(this).parents(".option_item").find("input").prop("checked")){
            if(!$(this).val().length){
                $(this).parents(".question").css("border","2px solid rgb(255, 153, 0)");
                $(this).parents(".question").find(".errorMessage").html('选择其他，请填写输入框');
            }else{
                if($(window).width()<800){
                    $(this).parents(".question").css("border-color","#f7f7f7");
                }else{
                    $(this).parents(".question").css("border-color","white");
                }
                $(this).parents(".question").find(".errorMessage").html('');
            }
        }
    });
    $(".survey_container").on("input",".underline",function(e){
        if($(this).val().length>50){
           
            $(this).parents(".question").css("border","2px solid rgb(255, 153, 0)");
            $(this).parents(".question").find(".errorMessage").html('字数超过限制，最大输入字数为50字');
        }else{
            if($(window).width()<800){
                $(this).parents(".question").css("border-color","#f7f7f7");
            }else{
                $(this).parents(".question").css("border-color","white");
            }
            $(this).parents(".question").find(".errorMessage").html('');
        }
    });
    var inputvalue1='',inputvalue2='';
    $(".survey_container").on('blur','.inputBMI',function(){

        inputvalue1=$.trim($(".question .inputBMI").eq(0).val());
        inputvalue2=$.trim($(".question .inputBMI").eq(1).val());

        if($(this).hasClass("inputHeight")){
            inputvalue1=$.trim($(this).val());
            if(!/^(([0-9]+)|([0-9]+\.[0-9]{1,3}))$/.test(inputvalue1)){
                $(this).parents(".question").css("border","2px solid rgb(255, 153, 0)");
                $(this).parents(".question").find(".errorMessage").html('请输入数字');
            }else{
                if(Number(inputvalue1)>=100&&Number(inputvalue1)<=250){
                    if($(window).width()<800){
                        $(this).parents(".question").css("border-color","#f7f7f7");
                    }else{
                        $(this).parents(".question").css("border-color","white");
                    }
                    $(this).parents(".question").find(".errorMessage").html('');
                    if(inputvalue2!=''){
                        BMI(inputvalue1,inputvalue2);
                    }
                }else{
                    $(this).parents(".question").css("border","2px solid rgb(255, 153, 0)");
                    $(this).parents(".question").find(".errorMessage").html('身高输入范围为100-250');
                }
                
            }
        }else if($(this).hasClass("inputWeight")){
            inputvalue2=$.trim($(this).val());
            if(!/^(([0-9]+)|([0-9]+\.[0-9]{1,3}))$/.test(inputvalue2)){
                $(this).parents(".question").css("border","2px solid rgb(255, 153, 0)");
                $(this).parents(".question").find(".errorMessage").html('请输入数字');
            }else{
                if(Number(inputvalue2)>=25&&Number(inputvalue2)<=150){
                    if($(window).width()<800){
                        $(this).parents(".question").css("border-color","#f7f7f7");
                    }else{
                        $(this).parents(".question").css("border-color","white");
                    }
                    $(this).parents(".question").find(".errorMessage").html('');
                    if(inputvalue1==''){
                        $(".question[data-id=2]").css("border","2px solid rgb(255, 153, 0)").find(".errorMessage").html('请填写身高');
                    }else{
                        BMI(inputvalue1,inputvalue2);
                    }
                }else{
                    $(this).parents(".question").css("border","2px solid rgb(255, 153, 0)");
                    $(this).parents(".question").find(".errorMessage").html('体重输入范围为25-150');
                }
                
            }
        }
    });
    $(".submitBtn").on("click",function(){
        if(validate()){
            if($(".underline").parents(".option_item").find('input[type=checkbox]').prop("checked")){

                if($.trim($(".underline").val()).length){
                    submitQA();
                }else{

                    $("html, body").animate({
                        scrollTop: $(".underline").parents(".question").offset().top
                    }, 600);
                    $(".underline").parents(".question").css("border","2px solid rgb(255, 153, 0)");
                    $(".underline").parents(".question").find(".errorMessage").html('选择其他，请填写输入框');
                }
            }else{
                submitQA();
            }
        }
    });
    $(".colseImg").on("click",function(){
        $(".qrcodeImg").hide();
    });
    $(".survey_container").on('click','.inputtext',function(e){
        e.stopPropagation();
        if($(window).width()<800){
                $(this).parents(".question").css("border-color","#f7f7f7");
            }else{
                $(this).parents(".question").css("border-color","white");
        }
        $(this).parents(".question").find(".errorMessage").html('');
    });
}

function BMI(inputvalue1,inputvalue2){
    if(!isNaN(Number(inputvalue1)) && !isNaN(Number(inputvalue2))){
        var inputheightValue=Number(inputvalue1)/100;
        var BMI=Number(inputvalue2)/(inputheightValue*inputheightValue);
        BMI=BMI.toFixed(2);
        var BMIStr='';
        var bmihtml=$('<span class="bmiHtml">您的BMI=<b style="color:#2695D0" class="bmiValue"></b>,属于<b class="bmiType" style="color:#2695D0"></b></span>');
        var bmiPs='<div class="bmiPs">注:BMI=体重(公斤)/身高(米)<sup>2</sup>,BMI是国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。</div>';
        if(BMI<18.5){
            BMIStr="偏瘦";
            if($(".question[type=99] .title>div").find(".bmiHtml").length){
                $(".question[type=99] .title .bmiHtml").find(".bmiValue").html(BMI);
                $(".question[type=99] .title .bmiHtml").find(".bmiType").html(BMIStr);
            }else{
                $(".question[type=99] .title>div").append(bmihtml);
                $(".question[type=99] .title .bmiHtml").find(".bmiValue").html(BMI);
                $(".question[type=99] .title .bmiHtml").find(".bmiType").html(BMIStr);
            }
        }else if(BMI>23.9){
            BMIStr="超重";
            if($(".question[type=99] .title>div").find(".bmiHtml").length){
                $(".question[type=99] .title .bmiHtml").find(".bmiValue").html(BMI);
                $(".question[type=99] .title .bmiHtml").find(".bmiType").html(BMIStr);
            }else{
                $(".question[type=99] .title>div").append(bmihtml);
                $(".question[type=99] .title .bmiHtml").find(".bmiValue").html(BMI);
                $(".question[type=99] .title .bmiHtml").find(".bmiType").html(BMIStr);
            }
        }else{
            BMIStr="正常";
            if($(".question[type=99] .title>div").find(".bmiHtml").length){
                $(".question[type=99] .title .bmiHtml").find(".bmiValue").html(BMI);
                $(".question[type=99] .title .bmiHtml").find(".bmiType").html(BMIStr);
            }else{
                $(".question[type=99] .title>div").append(bmihtml);
                $(".question[type=99] .title .bmiHtml").find(".bmiValue").html(BMI);
                $(".question[type=99] .title .bmiHtml").find(".bmiType").html(BMIStr);
            }
        }
        if(!$(".question[type=99]").find(".bmiPs").length){
            $(".question[type=99] .inputs").html(bmiPs);
        }
    }
}
var firstError=null;
function validate() {
    var b = true;
    firstError = null;
    $(".question:visible").each(function() {
        var d = $(this),
         a = validateQ(d);
        if (!a) {
            b = false;
        }
    });
    if (!b) {
        if (firstError) {
            $("html, body").animate({
                scrollTop: $(firstError).offset().top
            }, 600);
        }
    } else {}
    return b;
}
function validateQ(o) {
    var g = $(o).attr("req"),
        l = $(o).attr("type"),
        n = true,f='',inputflag=true;
        if(l=="radio"){
            n=false;
            $(o).find("input:checked").each(function(){
                n=true;
            });
        }else if(l=="checkbox"){
            n=false;
            $(o).find("input:checked").each(function(){
                if($(this).parent().attr("IsHavingOther")!=undefined){
                    inputflag=false;
                    if($.trim($(this).parent().find('.underline').val()).length){
                        inputflag=true;
                        n=true;
                    }
                }else{
                    n=true;
                }
            });
        }else if(l=="text"){
            n=false;
            var inputvalue=$.trim($(o).find("input").val());
            if(inputvalue.length){
                n=true;
            }
        }else if(l=="textarea"){
            n=false;
            var inputvalue=$.trim($(o).find(".inputtext").val());
            if(inputvalue.length){
                n=true;
            }
        }else if(l=="99"){
            n=false;
            var inputone=$.trim($(o).find(".inputBMI").eq(0).val());
            var inputtwo=$.trim($(o).find(".inputBMI").eq(1).val());
            if(inputone.length&&inputtwo.length){
                n=true;
            }
        }
    if(!n&&g=="1"){
        
        f = "此题是必答题";
        if(!inputflag){
            f="选择其他，请填写输入框";
        }
        if(!firstError){
            firstError=$(o)[0];
        }
        $("div.errorMessage",$(o)).html(f).show();
        $(o).css("border","2px solid rgb(255, 153, 0)");
    }else {
        $("div.errorMessage", $(o)).html('');
        if($(window).width()<800){
            $(o).css("border","2px solid #f7f7f7");
        }else{
            $(o).css("border","2px solid white");
        } 
    }
    if (f) {
        return false;
    }else{
        return true;
    }
    
}
function getQueryStringArgs() {
    var qs = (location.search.length > 0 ? location.search.substring(1) : '');
        var args = {};
        var items = qs.length ? qs.split('&') : [];
        var item = null;
        var name = null;
        var value = null;
        var i = 0;
        var len = items.length;
        for (i = 0; i < len; i++) {
            item = items[i].split('=');
            name = decodeURIComponent(item[0]);
            value = decodeURIComponent(item[1]);
            if (name.length) {
                args[name] = value;
            }
        }
        return args;
}
function getQuestion(){
    var args=getQueryStringArgs();
    if(args['tocken']!=undefined){
        Postdata.Key=args['tocken'];
    }else{
        Postdata.Key='';
    }
    if(args['serialId']!=undefined){
        Postdata.SerialId=args['serialId'];
    }else{
        Postdata.SerialId='';
    }
    if(args['memberId']!=undefined){
        Postdata.MemberId=args['memberId'];
    }else{
        Postdata.MemberId='';
    }
    if(args['returnurl']!=undefined){
        Postdata.ReturnUrl=args['returnurl'];
    }else{
        Postdata.ReturnUrl='';
    }
    if(args['jobnumber']!=undefined){
        Postdata.FactorNo=args['jobnumber'];
    }else{
        Postdata.FactorNo='';
    }
    $.ajax({
        type: 'Post',
        url: '/Question/GetInvestigInfo?InvestigNo=111&memId=123',
        data:'&data='+encodeURI(JSON.stringify(Postdata)),
        dataType:'json',
        timeOut:'600000',
        beforeSend:function(){
            $("#loading").show();
        },
        success: function(data){
            $("#loading").hide();
            if(data){
                jsonData=data;
                if(data.IsAlreadyAnswer){
                    getDialog();
                }else{
                    setQuestion(data);
                } 
                // setQuestion(data);
            }
        },
        complete: function(){
            $("#loading").hide();
        },
        error: function(){
            $("#loading").hide();
        }
    });
}

function aa(obj){
    if(!+[1,]){
        if($(obj).val().length>50){   
            $(obj).parents(".question").css("border","2px solid rgb(255, 153, 0)");
            $(obj).parents(".question").find(".errorMessage").html('字数超过限制，最大输入字数为50字');
        }else{
            if($(window).width()<800){
                $(obj).parents(".question").css("border-color","#f7f7f7");
            }else{
                $(obj).parents(".question").css("border-color","white");
            }
            $(obj).parents(".question").find(".errorMessage").html('');
        }
    } 
}

function setQuestion(data){
    var str=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    $("#survey_container").html('');
    if(data.AnswerRecords){
        var questions=data.AnswerRecords.AnswerQuestion;
        for(var i=0;i<questions.length;i++){
            var questionQ=questions[i].Question;
            var question='';
            if(questionQ.Type=="99"){
                question=$('<div class="question" type="'+questionQ.Type+'" data-id='+questionQ.QuestionId+'>\
                    <div class="title">\
                    <div>\
                    <div class="flex strong">\
                    <span class="num">'+questionQ.OrderNum+'</span>\
                    <div class="inputDiv">\
                        <span class="inputSpan">身高:<input type="text" class="inputBMI inputHeight">cm</span>\
                        <span class="inputSpan">体重:<input type="text" class="inputBMI inputWeight">kg</span>\
                     </div>\
                     </div>\
                     </div>\
                     </div>\
                     <div class="inputs heightInputs"></div></div>');
                $("#survey_container").append(question);
            }else{
                question=$('<div class="question" data-id='+questionQ.QuestionId+'><div class="title"><p><strong class="strong"><span class="num">'+questionQ.OrderNum+'</span>'+questionQ.QuestionTitle+'</strong></p></div><div class="inputs"></div></div>');
                $("#survey_container").append(question);
            }
            
            if(questionQ.IsRequired){
                $("#survey_container .question:last-child").find(".title .strong").append('<span class="required">*</span>');
                $("#survey_container .question:last-child").append('<div class="errorMessage"></div>');
                $("#survey_container .question:last-child").attr("req","1");
            }
            if(questionQ.Type=="0"){
                $("#survey_container .question:last-child").attr("type","text");
                var option_item='<div class="input_item"  OrderNum='+questionQ.OrderNum+'>\
                                        <input type="text" class="inputtext" id="q'+questionQ.OrderNum+'" name="q'+questionQ.OrderNum+'">\
                                    </div>';
                $("#survey_container .question:last-child").find(".inputs").html(option_item);
                if(questions[i].Answer){
                    $("#survey_container .question:last-child").find(".inputs .inputtext").val(questions[i].Answer[0].OtherValue);
                }
            }else if(questionQ.Type=="1"){
                $("#survey_container .question:last-child").attr("type","radio");
                var option_item='';
                for(var j=0;j<questionQ.QuestionItem.length;j++){
                    var item=questionQ.QuestionItem[j];
                    var relid='q'+questionQ.OrderNum+'_'+item.OrderNum;
                    option_item=option_item+'<div class="option_item" IsMutex="'+item.IsMutex+'" ItemNo='+item.ItemNo+' OrderNum='+item.OrderNum+'>\
                                        <a href="javascript:" class="jqRadio" rel="'+relid+'"></a>\
                                        <input style="display:none;" type="radio" name="q'+questionQ.OrderNum+'" id="'+relid+'" value="'+item.ItemNo+'">\
                                        <label for="'+relid+'">'+str[j]+'<span>'+item.Content+'</span></label>\
                                    </div>';
                }
                $("#survey_container .question:last-child").find(".inputs").html(option_item);
                if(questions[i].Answer){
                    var QAnswer=questions[i].Answer;
                    for(var k=0;k<QAnswer.length;k++){
                        var $item=$("#survey_container .question:last-child").find('.option_item[ItemNo="'+QAnswer[k].ItemNo+'"]');
                        $item.find("a").addClass("jqChecked");
                        $item.find('input').prop("checked",true);
                    }
                }
            }else if(questionQ.Type=="2"){
                $("#survey_container .question:last-child").attr("type","checkbox").find(".title strong").append('<span class="moreSelect">[多选题]</span>');
                var option_item='';
                for(var j=0;j<questionQ.QuestionItem.length;j++){
                    var item=questionQ.QuestionItem[j];
                    var relid='q'+questionQ.OrderNum+'_'+item.OrderNum;
                    if(item.IsHavingOther){
                        option_item=option_item+'<div class="option_item" IsMutex="'+item.IsMutex+'" IsHavingOther="1" ItemNo='+item.ItemNo+' OrderNum='+item.OrderNum+'>\
                                        <a href="javascript:" class="jqCheckbox" rel="'+relid+'"></a><input style="display:none;" id="'+relid+'" type="checkbox" name="q'+questionQ.OrderNum+'" value="'+item.ItemNo+'">\
                                        <label style="display: inline-block;">'+str[j]+'<span>'+item.Content+'</span></label> <div class="inputother"><input onpropertychange="aa(this)" class="underline" value="" type="text" rel="'+relid+'"></div>\
                                    </div>';

                    }else{
                        option_item=option_item+'<div class="option_item" IsMutex="'+item.IsMutex+'" ItemNo='+item.ItemNo+' OrderNum='+item.OrderNum+'>\
                                        <a href="javascript:" class="jqCheckbox" rel="'+relid+'"></a>\
                                        <input style="display:none;" type="checkbox" name="q'+questionQ.OrderNum+'" id="'+relid+'" value="'+item.ItemNo+'">\
                                        <label for="'+relid+'">'+str[j]+'<span>'+item.Content+'</span></label>\
                                    </div>';
                    }
                    
                }
                $("#survey_container .question:last-child").find(".inputs").html(option_item);
                if(questions[i].Answer){
                    var QAnswer=questions[i].Answer;
                    for(var k=0;k<QAnswer.length;k++){
                        var $item=$("#survey_container .question:last-child").find('.option_item[ItemNo="'+QAnswer[k].ItemNo+'"]');
                        $item.find("a").addClass("jqChecked");
                        $item.find('input[type="checkbox"]').prop("checked",true);
                        if($item.attr("IsHavingOther")!=undefined){
                            $item.find('input[type="text"]').val(QAnswer[k].OtherValue);
                        }
                    }
                }
            }else if(questionQ.Type=="3"){
                $("#survey_container .question:last-child").attr("type","textarea");
                var option_item='<div class="input_item"  OrderNum='+questionQ.OrderNum+'>\
                                        <textarea name="q'+questionQ.OrderNum+'" id="q'+questionQ.OrderNum+'" cols="30" rows="4" class="inputtext"></textarea>\
                                    </div>';
                $("#survey_container .question:last-child").find(".inputs").html(option_item);
                if(questions[i].Answer){
                    $("#survey_container .question:last-child").find(".inputs .inputtext").val(questions[i].Answer[0].OtherValue);
                }
            }else if(questionQ.Type=="4"){
                $("#survey_container .question:last-child").attr("type","4");
                var option_item='';
                for(var j=0;j<questionQ.QuestionItem.length;j++){
                    var item=questionQ.QuestionItem[j];
                    var relid='q'+questionQ.OrderNum+'_'+item.OrderNum;
                    option_item=option_item+'<div class="option_item" ItemNo='+item.ItemNo+' OrderNum='+item.OrderNum+'>\
                                        <a href="javascript:" class="jqRadio" rel="'+relid+'"></a>\
                                        <input style="display:none;" type="radio" name="q'+questionQ.OrderNum+'" id="'+relid+'" value="'+item.ItemNo+'">\
                                        <label for="'+relid+'">'+str[j]+'<span>'+item.Content+'</span></label>\
                                    </div>';
                }
                $("#survey_container .question:last-child").find(".inputs").html(option_item);
                if(questions[i].Answer){
                    var QAnswer=questions[i].Answer;
                    for(var k=0;k<QAnswer.length;k++){
                        var $item=$("#survey_container .question:last-child").find('.option_item[ItemNo="'+QAnswer[k].ItemNo+'"]');
                        $item.find("a").addClass("jqChecked");
                        $item.find('input').prop("checked",true);
                    }
                }
                $("#survey_container .question:last-child").find(".inputs input[type=radio]").attr("disabled","disabled");
            }
        }
        $(".submitDiv").show();
    }
}

function submitQA(){
    var submitQuestionnaire = {};
    submitQuestionnaire.SerialId = Postdata.SerialId;
    submitQuestionnaire.MemberId = Postdata.MemberId;
    submitQuestionnaire.Key = Postdata.Key;
    submitQuestionnaire.FactorNo = Postdata.FactorNo;
    jsonData.AnswerRecords.AnswersTime=new Date();
    $(".question:visible").each(function(index,item){
        if($(item).attr("type")=="radio"||$(item).attr("type")=="4"){
            var answers=[];
            $(item).find("input:checked").each(function(index,Qitem){
                var answerItem={};
                answerItem.QuestionId=$(item).attr("data-id");
                answerItem.ItemNo=$(Qitem).parent().attr("ItemNo");
                answerItem.OrderNum=$(Qitem).parent().attr("OrderNum");
                answerItem.Content=$(Qitem).next().find('span').text();
                answers.push(answerItem);
            });
        jsonData.AnswerRecords.AnswerQuestion[index].Answer=answers;
        }else if($(item).attr("type")=="checkbox"){
            var answers=[];
            $(item).find("input[type=checkbox]:checked").each(function(index,Qitem){
                var answerItem={};
                answerItem.QuestionId=$(item).attr("data-id");
                answerItem.ItemNo=$(Qitem).parent().attr("ItemNo");
                answerItem.OrderNum=$(Qitem).parent().attr("OrderNum");
                answerItem.Content=$(Qitem).next().find('span').text();
                if($(Qitem).parent().attr("IsHavingOther")!=undefined){
                    answerItem.OtherValue=$.trim($(Qitem).siblings(".inputother").find('input[type=text]').val());
                }else{
                    answerItem.OtherValue='';
                }
                answers.push(answerItem);
            });
        jsonData.AnswerRecords.AnswerQuestion[index].Answer=answers;
        }else if($(item).attr("type")=="text"){
            var answers=[];
            var answerItem={};
            answerItem.QuestionId=$(item).attr("data-id");
            answerItem.OrderNum=$(item).find('.input_item').attr("OrderNum");
            answerItem.OtherValue=$.trim($(item).find('.inputtext').val());
            answers.push(answerItem);
        jsonData.AnswerRecords.AnswerQuestion[index].Answer=answers;
        }else if($(item).attr("type")=="textarea"){
            var answers=[];
            var answerItem={};
            answerItem.QuestionId=$(item).attr("data-id");
            answerItem.OrderNum=$(item).find('.input_item').attr("OrderNum");
            answerItem.OtherValue=$.trim($(item).find('.inputtext').val());
            answers.push(answerItem);
        jsonData.AnswerRecords.AnswerQuestion[index].Answer=answers;
        }else if($(item).attr("type")=="99"){
            var answers=[];
            var answerItem={};
            answerItem.QuestionId=$(item).attr("data-id");
            answerItem.Content=$.trim($(item).find('.inputHeight').val());
            var answerItem1={};
            answerItem1.QuestionId=$(item).attr("data-id");
            answerItem1.Content=$.trim($(item).find('.inputWeight').val());
            var answerItem2={};
            answerItem2.QuestionId=$(item).attr("data-id");
            answerItem2.Content=$(item).find(".bmiValue").html();
            var answerItem3={};
            answerItem3.QuestionId=$(item).attr("data-id");
            answerItem3.Content=$(item).find(".bmiType").html();
            answers.push(answerItem);
            answers.push(answerItem1);
            answers.push(answerItem2);
            answers.push(answerItem3);
        jsonData.AnswerRecords.AnswerQuestion[index].Answer=answers;
        }
    });
    submitQuestionnaire.AnswerRecords = jsonData.AnswerRecords;
     // console.log(submitQuestionnaire);
    $.ajax({
        type: 'Post',
        url: '/question/EditInvestigInfo',
        data: '&saveJson=' + encodeURI(JSON.stringify(submitQuestionnaire)),
        success:function(data){
            var resData=JSON.parse(data);
            if(resData.ResponsesCode==100){
                alert("提交成功！");
                if(Postdata.ReturnUrl!=''){
                    Postdata.ReturnUrl=qrlink.substr((qrlink.indexOf("returnurl")+10));
                    // console.log(Postdata.ReturnUrl);
                    window.location.href=Postdata.ReturnUrl;    
                }
            }else if(resData.ResponsesCode==111){
                alert("已经提交过，无需重复提交");
            }
        },
        complete: function(data) {
        },
        error: function(a){
            console.log(a);
        }
    });
}
function getDialog(){
    var dialog=$('<div class="dialog"><p>您已提交过</p><div><div class="submit submitOrder">查看订单</div><div class="submit submitAnswer">查看答案</div></div></div>');
    dialog.find(".submitOrder").on("click",function(){
        dialog.fadeOut(function () {
            dialog.remove();
        });
        window.location.href="https://m.ly.com/scenery/helthorderinfo.html?orderMemberId=tcwvmid&tcwvclogin&orderSerialId="+Postdata.SerialId;
    });
    dialog.find(".submitAnswer").on("click",function(){
        dialog.fadeOut(function () {
            dialog.remove();
        });
        window.location.href=qrlink.replace("blhealth","blhealthdetail");
    });
    $("body").append(dialog);
}
